package main

func getMax(a int, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func getMin(a int, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func maxProduct(nums []int) int {
	max := make([]int, len(nums))
	max[0] = nums[0]
	min := make([]int, len(nums))
	min[0] = nums[0]
	result := nums[0]
	for i := 1; i < len(nums); i++ {
		if nums[i] > 0 {
			max[i] = getMax(max[i-1]*nums[i], nums[i])
			min[i] = getMin(min[i-1]*nums[i], nums[i])
		} else {
			max[i] = getMax(min[i-1]*nums[i], nums[i])
			min[i] = getMin(max[i-1]*nums[i], nums[i])
		}

		if result < max[i] {
			result = max[i]
		}
	}
	return result
}

func main() {
	println(maxProduct([]int{7, -2, -4}))
}
